package com.yuanshen.receive;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author 朱厚强
 * @version 1.0
 * @classname DelayListener
 * 延迟交换机监听器类
 * 该类定义了一个RabbitMQ的延迟消息监听器
*/
@Component
@Slf4j
public class DelayListener {
    // 定义一个方法，用于监听延迟消息
    @RabbitListener(
            // 配置监听的队列和交换机
            bindings = @QueueBinding(
                    value = @Queue(value = "delay.queue", durable = "true"), // 定义队列名称和持久性
                    exchange = @Exchange(value = "delay.direct", delayed = "true"), // 定义交换机名称和延迟特性
                    key = "delay" // 路由键
            )
    )
    public void listenDelayQueue(String message){
        // 当监听到消息时，执行此方法
        log.info("监听到delay延迟消息, {}", message); // 记录日志
    }
}
